package com.example.myapplication.tack_10.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_10.NewRequestActivity;
import com.example.myapplication.tack_10.XQActivity;
import com.example.myapplication.tack_10.data.ArrangeData;
import com.example.myapplication.tack_10.data.FenLeiShuQiuData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class FenLeiSuQiuAdapter extends RecyclerView.Adapter<FenLeiSuQiuAdapter.My> {
    private List<FenLeiShuQiuData.RowsDTO> list;
    private Context context;
    private View view;

    public FenLeiSuQiuAdapter(List<FenLeiShuQiuData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.news_list,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL + list.get(position).getImgUrl()).into(holder.imags);
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(list.get(position).getUndertaker());
        if("0".equals(list.get(position).getState())){
            holder.commentNum.setText("未处理");
        }else  if("1".equals(list.get(position).getState())){
            holder.commentNum.setText("已处理");
        }

        holder.publishDate.setText(list.get(position).getCreateTime());
        holder.list.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, XQActivity.class);
                String id = String.valueOf(list.get(position).getId());
                intent.putExtra(Common.COMMON,id);
                context.startActivity(intent);


            }
        });

    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView title;
        private TextView content;
        private TextView commentNum;
        private TextView publishDate;
        private LinearLayout list;
        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            title = view.findViewById(R.id.title);
            content = view.findViewById(R.id.content);
            commentNum = view.findViewById(R.id.commentNum);
            publishDate = view.findViewById(R.id.publishDate);
            list = view.findViewById(R.id.list);
        }
    }
}
